package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.example.service.TrService;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

public class TrCacheServiceImpl<M extends BaseMapper<T>, T> extends CacheServiceImpl<M, T> implements TrService<T> {


    public boolean removeByIds(Long userId, Collection<? extends Serializable> idList) {

        UpdateWrapper<T> update = new UpdateWrapper<>();
        update.in("id", idList);
        update.set("update_id", userId);
        update.set("update_time", new Date());

        boolean updateRet = super.update(update);

        // 清理缓存
        if(updateRet) {
            super.clearCache();
        }

        return updateRet;
    }

    @Override
    public boolean updateById(T entity) {
        // TODO Auto-generated method stub
        boolean update =  super.updateById(entity);

        if(update) {
            super.clearCache();
        }

        return update ;
    }

    @Override
    public boolean save(T entity) {
        // TODO Auto-generated method stub
        boolean save = super.save(entity);

        if(save) {
            super.clearCache();
        }
        return save ;
    }
 

}
